home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 5 / Example 5.10 / Debug / Shaders / terrain.ps < prev    next >
Encoding:
Text File  |  2006-06-22  |  1.2 KB  |  34 lines

  1. //////////////////////////////////////////////////////////////////////////
  2. //                                                                      //
  3. //               Terrain Texture Splatting Pixelshader                  //
  4. //                                                                      //
  5. //                   Written by C. Granberg, 2006                       //
  6. //                                                                      //
  7. //////////////////////////////////////////////////////////////////////////
  8.  
  9. sampler alpha;
  10. sampler texture1;
  11. sampler texture2;
  12. sampler texture3;
  13. sampler light;
  14.  
  15. float4 Main(float2 alphaUV : TEXCOORD0, float2 colorUV : TEXCOORD1, float shade : TEXCOORD2) : COLOR
  16. {
  17.     //Sample the textures
  18.     float4 a  = tex2D(alpha, alphaUV);
  19.     float4 c1 = tex2D(texture1, colorUV);
  20.     float4 c2 = tex2D(texture2, colorUV);
  21.     float4 c3 = tex2D(texture3, colorUV);
  22.     float4 l  = tex2D(light, alphaUV);
  23.  
  24.     //Calculate the inverse
  25.     float inverse = 1.0f / (a.r + a.g + a.b);
  26.     
  27.     //Multiply with alpha texture
  28.     c1 *= a.b * inverse;
  29.     c2 *= a.g * inverse;
  30.     c3 *= a.r * inverse;
  31.  
  32.     //Return result
  33.     return (c1 + c2 + c3) * shade * l;
  34. }